// <copyright file="GoogleTask.cs">
// Copyright (c) Chad Weimer
// </copyright>
// <author>Chad Weimer</author>
// <summary>
// This file is part of Tasx.
//
// Tasx is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tasx is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tasx.  If not, see http://www.gnu.org/licenses/.
// </summary>

using System;
using System.Xml;
using Tasx.Definitions;
using GTask = Google.Apis.Tasks.v1.Data.Task;

namespace Tasx.Providers.GoogleTasks
{
	public class GoogleTask : Task
	{
		internal GoogleTask(GoogleTaskProvider provider, GTask googleTask)
			: base(provider)
		{
			//provider.VerifyNotNull("provider");
			//googleTask.VerifyNotNull("googleTask");

			Internal = googleTask;
		}

		public override System.Collections.Generic.IEnumerable<ITask> Tasks
		{
			get
			{
				throw new NotImplementedException();
			}
		}

		public override string Summary
		{
			get { return Internal.Title; }
			set { Internal.Title = value; }
		}

		public override TimeSpan? Reminder
		{
			get { return null; }
			set { ; }
		}

		public override TaskPriority Priority
		{
			get
			{
				throw new NotImplementedException();
			}
			set
			{
				throw new NotImplementedException();
			}
		}

		public override string Notes
		{
			get { return Internal.Notes; }
			set { Internal.Notes = value; }
		}

		public override DateTime? DueDate
		{
			get
			{
				if (string.IsNullOrEmpty(Internal.Due))
				{
					return null;
				}
				return XmlConvert.ToDateTime(Internal.Due, XmlDateTimeSerializationMode.Utc);
			}
			set
			{
				if (!value.HasValue)
				{
					Internal.Due = null;
				}
				Internal.Due = XmlConvert.ToString(value.Value, XmlDateTimeSerializationMode.Utc);
			}
		}

		public override bool Completed
		{
			get
			{
				return !string.IsNullOrEmpty(Internal.Completed);
			}
			set
			{
				if (value)
				{
					Internal.Completed = XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Utc);
				}
				else
				{
					Internal.Completed = null;
				}
			}
		}

		internal GTask Internal { get; private set; }
	}
}
